package com.woniuxy.creditsystem.systemmag.service.impl;

import com.woniuxy.creditsystem.common.bean.CompanyInfo;
import com.woniuxy.creditsystem.common.mapper.CompanyMapper;
import com.woniuxy.creditsystem.systemmag.service.ICompanyService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(readOnly = true)
public class CompanyServiceImpl implements ICompanyService {

    @Resource
    private CompanyMapper companyMapper;

    /**
     * 新增数据
     * */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int save(CompanyInfo com) {
        if (com.getName() == null ||com.getSimpleName() == null){
            throw new NullPointerException();
        }
        return companyMapper.save(com);
    }

    /**
     * 查询数据
     * */
    @Override
    public List<CompanyInfo> findAll() {
        return companyMapper.findAll();
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int delete(long id) {
        return companyMapper.delete(id);
    }

}
